package com.wecon.springdemo.service.impl;

import com.wecon.springdemo.bean.User;
import com.wecon.springdemo.bean.UserExample;
import com.wecon.springdemo.mapper.UserMapper;
import com.wecon.springdemo.service.ManagerUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Weikang  Wang
 * @program: com.wecon.springdemo.service.impl
 * @description:
 * @date 2020/4/28 17:47
 */
@Service
public class ManagerUserServiceImpl implements ManagerUserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User getUserByName(String name) {

        UserExample example = new UserExample();
        example.or().andNickNameEqualTo(name);
        List<User> users = userMapper.selectByExample(example);

        if (users.isEmpty()) {
            return null;
        }

        return users.get(0);
    }
}
